<template>
  <div class="vxe-table">
    <table>
      <thead>
        <tr>
          <th v-for="column in tableColumns" :key="column.field">{{ column.title }}</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="row in tableData" :key="row.id">
          <td v-for="column in tableColumns" :key="column.field">{{ row[column.field] }}</td>
        </tr>
      </tbody>
    </table>
    <div class="pagination">
      <button @click="prevPage">Previous</button>
      <span>{{ PageObj.currentPage }} / {{ totalPages }}</span>
      <button @click="nextPage">Next</button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'VxeTable',
  props: {
    tableColumns: {
      type: Array,
      required: true
    },
    tableData: {
      type: Array,
      required: true
    },
    PageObj: {
      type: Object,
      required: true
    }
  },
  computed: {
    totalPages() {
      return Math.ceil(this.PageObj.total / this.PageObj.pageSize);
    }
  },
  methods: {
    prevPage() {
      if (this.PageObj.currentPage > 1) {
        this.$emit('onPageChange', this.PageObj.currentPage - 1, this.PageObj.pageSize);
      }
    },
    nextPage() {
      if (this.PageObj.currentPage < this.totalPages) {
        this.$emit('onPageChange', this.PageObj.currentPage + 1, this.PageObj.pageSize);
      }
    }
  }
};
</script>

<style scoped>
.vxe-table {
  width: 100%;
  border-collapse: collapse;
}

.vxe-table th, .vxe-table td {
  border: 1px solid #ddd;
  padding: 8px;
}

.vxe-table th {
  background-color: #f2f2f2;
}

.pagination {
  margin-top: 10px;
  text-align: center;
}
</style>